import { HoleStandard } from "./HoleStandard";
import { holeShowType, holeStandard, holeType, holeValue, labelShowType, labelTypesParas } from "./HoleTypeStore";
import { standardStore } from "./HoleStandardStore";
import { standardSizeStore } from "./HoleStandardSizeStore";

class HoleManager {
  constructor() {
    this.holeStandards = [];
    this.holeStandard = null;
    this.init();
  }
  // 判断是否变换孔类型
  isChangeHoleType(holeType) {
    if (this.holeStandard) {
      return this.holeStandard.holeTypeValue === holeType;
    }
    return false
  }

  // 获取大小列表
  getHoleStandardSizeOption(standardValue, holeTypeValue, standardType) {
    if (!this.holeStandard) {
      this.holeStandard = this.getHoleByValue(holeTypeValue);
    }
    return this.holeStandard.getSizeOptions(standardValue, standardType);
  }

  // 获取标准列表
  getStandardOptionsByValue(holeTypeValue = -1, standardType) {
    if (!this.holeStandard) {
      this.holeStandard = this.getHoleByValue(holeTypeValue);
    }
    return this.holeStandard.getStandardOptions(standardType);
  }

  // 获取统一存在的参数名
  getShowTypes(standardValue) {
    if(standardValue === -1){
      return []
    }
    return this.holeStandard.getShowTypes(standardValue);
  }

  // 获取孔数据中的标签名
  getLabelShowTypes() {
    return this.holeStandard.getLabelShowTypes();
  }

  // 获取标签列表
  getLabelTypeObj() {
    return this.holeStandard.labelShowTypes;
  }

  // 获取孔数据
  getHoleByValue(holeTypeValue) {
    return this.holeStandards.find(hole => hole.holeTypeValue === holeTypeValue);
  }

  // 设置当前孔数据
  setHoleByHoleType(holeTypeValue) {
    if (this.holeStandard) {
      this.holeStandard = null;
    }
    this.holeStandard = this.holeStandards.find(hole => hole.holeTypeValue === holeTypeValue);
  }

  // 获取所有孔数据
  getAllHole() {
    return this.holeStandards;
  }

  // 获取当前孔数据
  getHoleParas() {
    return this.holeStandard
  }

  reset() {
    if (this.holeStandard) {
      this.holeStandard = null;
    }
  }

  init() {
    this.holeStandards = [
      // 沉头孔 -- 2
      new HoleStandard({
        holeType: holeType.COUNTERBORE_HOLE,
        holeTypeValue: holeValue.COUNTERBORE_HOLE,
        sizeOptions: standardSizeStore.COUNTERBORE_HOLE,
        standardOptions: standardStore.COUNTERBORE_HOLE,
        showTypes: [holeShowType.mate,],
        labelShowTypes: new labelTypesParas(null, labelShowType.cbDeep, labelShowType.cbDiameter),
        specialShowTypes: [],
        specialHideTypes: [],
      }),
      // 锥形沉孔 -- 4
      new HoleStandard({
        holeType: holeType.COUNTERSUNK_HOLE,
        holeTypeValue: holeValue.COUNTERSUNK_HOLE,
        sizeOptions: standardSizeStore.COUNTERSUNK_HOLE,
        standardOptions: standardStore.COUNTERSUNK_HOLE,
        showTypes: [
          holeShowType.mate,
        ],
        labelShowTypes: new labelTypesParas(labelShowType.headAngle, null, labelShowType.headDiameter),
        specialShowTypes: [],
        specialHideTypes: [],
      }),
      // 简单孔 -- 0
      new HoleStandard({
        holeType: holeType.SIMPLE_HOLE,
        holeTypeValue: holeValue.SIMPLE_HOLE,
        sizeOptions: standardSizeStore.SIMPLE_HOLE,
        standardOptions: standardStore.SIMPLE_HOLE,
        showTypes: [],
        labelShowTypes: new labelTypesParas(),
        specialShowTypes: [
          {
            type: holeShowType.mate,
            value: 2,
          }
        ],
        specialHideTypes: [],
      }),
      // 螺纹孔 -- 7
      new HoleStandard({
        holeType: holeType.THREADED_HOLE,
        holeTypeValue: holeValue.THREADED_HOLE,
        sizeOptions: standardSizeStore.THREADED_HOLE,
        standardOptions: standardStore.THREADED_HOLE,
        showTypes: [
          holeShowType.isShow,
        ],
        labelShowTypes: new labelTypesParas(),
        specialShowTypes: [],
        specialHideTypes: [],
      }),
      // 锥形管螺纹 -- 8
      new HoleStandard({
        holeType: holeType.COUNTER_THREADED,
        holeTypeValue: holeValue.COUNTER_THREADED,
        sizeOptions: standardSizeStore.COUNTER_THREADED,
        standardOptions: standardStore.COUNTER_THREADED,
        showTypes: [
          holeShowType.isShow,
        ],
        labelShowTypes: new labelTypesParas(),
        specialShowTypes: [],
        specialHideTypes: [],
      }),
    ];
  }

}

const holeManager = new HoleManager();
export {holeManager};

